// 引入axios来处理ajax请求
import axios from 'axios'
axios.defaults.baseURL = "http://192.168.1.220:8003"
// axios.defaults.baseURL = "http://test.mmcard.cn:7200"
// 下面是接口请求的函数
export default {
  // 公共组件接口 ----------------
  // 获取代理商信息---Admin
  getAgentInformation(myToken) {
    return axios({
      url: `UserInfo/PTTheUserBasicInformation?key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 首页接口
  // 获取公告列表
  getNoticeList(pageSize) {
    return axios({
      url: `http://www.decerp.cc/MessageBox/GetCommonMessageBoxList?pageIndex=1&pageSize=${pageSize}`
    }).then(res => {
      return res.data.values
    })
  },
  // 获取订单增减情况
  getOrderUpsAndDowns(myToken) {
    return axios({
      url: `UserInfo/GetPTYesterdayTodayTotal?key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 获取反馈列表
  getFeedbackList(pageIndex, pageSize, myToken) {
    return axios({
      url: `UserInfo/PTGetPageUserFeedbackList?pageIndex=${pageIndex}&pageSize=${pageSize}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 登陆页接口
  // 登录
  login(data) {
    return axios({
      method: "POST",
      url: `/UserInfo/AppLogin`,
      headers: {
        "Content-Type": "application/json"
      },
      data
    }).then(res => {
      return res.data
    })
  },
  // 公共组件接口 ----------------

  // 商户管理页面接口 ----------------
  // 我的商户页面
  // 获取商户列表
  getBusinesslistings(pageIndex, pageSize, search, urlParameter, myToken) {
    return axios({
      url: `/UserInfo/PTGetUserList?page=${pageIndex}&pagesize=${pageSize}&name=${search}&status=${urlParameter.status||""}&MsgNo=${urlParameter.MsgNo||""}&nreg_sdate=${urlParameter.nreg_sdate||""}&nreg_edate=${urlParameter.nreg_edate||""}&exp_sdate=${urlParameter.exp_sdate||""}&exp_edate=${urlParameter.exp_edate||""}&sv_versionid=${urlParameter.sv_versionid||""}&sv_versionname=${urlParameter.sv_versionname||""}&lastloginday=${urlParameter.lastloginday||""}&storetype=${urlParameter.storetype||""}&multipletype=${urlParameter.multipletype||""}&dec_payment_method=${urlParameter.dec_payment_method||""}&nearexpiration=${urlParameter.nearexpiration||""}&sub_distributor_id=${urlParameter.sub_distributor_id||""}&code=${urlParameter.code||""}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },

  // 商户详情页面
  // 获取商户详情
  getMerchantDetails(user_id, myToken) {
    return axios({
      url: `/UserInfo/PTGetUserDetail?user_id=${user_id}&key=${myToken}`
    }).then(res => {
      if (res.data.succeed) {
        return res.data
      } else {
        Promise.reject(res)
      }
    });
  },
  // 禁用店铺
  disableTheStore(user_id, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTProhibit?user_id=${user_id}&key=${myToken}`
    }).then(res => {
      return res.data.succeed
    });
  },
  // 启用店铺
  enableTheStore(user_id, myToken, acountno) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTEnable?user_id=${user_id}&key=${myToken}&acountno=${acountno}`
    }).then(res => {
      return res.data.succeed
    });
  },
  // 获取增值服务开通情况
  getValueAddedServices(user_id, type, code, myToken) {
    return axios({
      url: `/UserInfo/GetPTValueAddedPackage?user_id=${user_id}&type=${type}&code=${code}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 短信充值/回收 
  SmsHandle(user_id, sms_mealnum, sms_amount, sms_remark, type, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTInsertSns_orderByDistributor?user_id=${user_id}&sms_mealnum=${sms_mealnum}&sms_amount=${sms_amount}&sms_remark=${sms_remark}&type=${type}&key=${myToken}`
    }).then(res => {
      if (res.data.succeed) {
        return res.data
      } else {
        Promise.reject(res)
      }
    });
  },

  // 新增商户页面
  // 根据ID获取软件版本
  accordingToIdGetVersion(id, is_add, myToken) {
    return axios({
      url: `/UserInfo/PTGteStoreVersion?id=${id}&is_add=${is_add}&key=${myToken}`
    }).then(res => {
      const {
        values,
        succeed
      } = res.data;
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 根据版本类型获取版本
  accordingToVersionTypeGetVersion(code, guid, myToken) {
    return axios({
      url: `/UserInfo/PTPackageVersion_newV2?code=${code}&guid=${guid}&is_add=true&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 获取客服/经理数据
  getManagerData(myToken) {
    return axios({
      url: `/UserInfo/PTGetDistributorUserList?page=1&pagesize=100&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 获取行业数据
  getIndustryData(myToken) {
    return axios({
      url: `/UserInfo/PTGetIndustryType?key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 新增保存/保存修改
  SaveTheChanges(data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTOperate?key=${myToken}`,
      data
    }).then(res => {
      return res.data
    });
  },

  // 升级续费页面
  // 获取连锁店铺分店
  obtainChainStoreBranches(userid, myToken) {
    return axios({
      url: `/UserInfo/PTGetStorelist?userid=${userid}&StorePageState=0&versionid=3&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 版本升级续费
  versionUpgradeRenewal(user_id, ordercode, data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTSaveOrder?user_id=${user_id}&ordercode=${ordercode}&key=${myToken}`,
      data
    }).then(res => {
      return res.data.values
    });
  },

  // 增值服务页面
  // 购买增值服务
  purchaseValueAdded(user_id, data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTDistributorBuyFuncList?user_id=${user_id}&key=${myToken}`,
      data
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },

  // 过期商户页面
  // 发送短信
  sendSms(data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTSendSms?key=${myToken}`,
      data
    }).then(res => {
      return res.data
    });
  },
  // 商户管理页面接口 ----------------

  // 商户调整页面接口 ----------------
  // 获取服务商
  getService(myToken) {
    return axios({
      url: `/UserInfo/PTGetDistributorList?key=${myToken}`
    }).then(res => {
      return res.data
    });
  },
  // 查找商户
  FindMerchantsByAccount(sv_ul_acountno, myToken) {
    return axios({
      url: `/UserInfo/GetUserShopByacountno?sv_ul_acountno=${sv_ul_acountno}&key=${myToken}`
    }).then(res => {
      return res.data.values
    });
  },
  // 调整服务商
  adjustmentService(newdistributor_id, user_id, orgnewdistributor_id, myToken) {
    return axios({
      url: `/UserInfo/ChangeDistributor?newdistributor_id=${newdistributor_id}&user_id=${user_id}&orgnewdistributor_id=${orgnewdistributor_id}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 通过账号查找商户版本
  findMerchantByVersion(criteria, myToken) {
    return axios({
      url: `/UserInfo/PTGetStoreVersion?criteria=${criteria}&key=${myToken}`
    }).then(res => {
      return res.data
    });
  },
  // 版本调整
  versionToAdjust(orgVersionid, newVersionid, updateReason, user_id, myToken) {
    return axios({
      url: `/UserInfo/PTUpdateStoreVersion?orgVersionid=${orgVersionid}&newVersionid=${newVersionid}&updateReason=${updateReason}&user_id=${user_id}&key=${myToken}`
    }).then(res => {
      return res.data
    });
  },
  // 商户调整页面接口 ----------------

  // 订单管理页面接口 ----------------
  // 软件订单页面
  // 获取软件订单数据
  getVersionOrderData(pageIndex, pageSize, search, myToken) {
    return axios({
      url: `/UserInfo/PTGetOrderList?page=${pageIndex}&pagesize=${pageSize}&seachStr=${search}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },

  // 增值订单页面
  // 获取增值订单数据
  getAppreciationOrderData(pageIndex, pageSize, sv_order_state, user_id, order_id, search, myToken) {
    return axios({
      url: `/UserInfo/PTGetValuesRecordPageListByUserId?page=${pageIndex}&pagesize=${pageSize}&sv_order_state=${sv_order_state}&user_id=${user_id}&order_id=${order_id}&query_vague=${search}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },

  // 短信订单页面
  // 获取短信订单数据
  getMsmOrderData(pageIndex, pageSize, search, myToken) {
    return axios({
      url: `/UserInfo/PTGetGiftsmsRecordPageListByUserId?page=${pageIndex}&pagesize=${pageSize}&seachStr=${search}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 查询短信订单未完成原因
  querySmsOrderUnfinished(id, myToken) {
    return axios({
      url: `/UserInfo/GetDecSMSorderstate?key=${myToken}&id=${id}`
    }).then(res => {
      return res.data
    });
  },
  // 短信订单撤回
  msmOrderRecall(smsOrder, myToken) {
    return axios({
      url: `/UserInfo/PTSns_orderCancelByDistributor?key=${myToken}&sms_ordenum=${smsOrder}`,
      method: "POST"
    }).then(res => {
      return res.data
    });
  },

  // 短信变动记录页面
  // 获取短信变动订单数据
  getMsmChangesOrderData(pageIndex, pageSize, search, myToken) {
    return axios({
      url: `/UserInfo/PTGetSnsCancelOrderList/?page=${pageIndex}&pagesize=${pageSize}&seachStr=${search}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 订单管理页面接口 ----------------

  // 待办事项页面接口 ----------------
  // 小程序申请记录页面
  // 获取小程序/支付申请列表
  getAppletApplicationList(page, pagesize, type, search, myToken) {
    return axios({
      url: `/UserInfo/PTGetWxAppApplicationPageListByDistributorId?page=${page}&pagesize=${pagesize}&type=${type}&status=-1&search=${search}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 下载资料
  downloadInformation(data, id, refix) {
    return axios({
      method: "POST",
      url: `http://res.decerp.cc/api/Images/DownLoadBatchImgs?id=${id}&type=1&refix=${refix}`,
      data
    }).then(res => {
      return res.data
    })
  },
  // 小程序审核
  appletAudit(id, status, myToken) {
    return axios({
      url: `/UserInfo/PTApproveWxAppApplication?user_id=47116375&id=${id}&status=${status}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 创建小程序页面
  // 图片上传接口
  /**
   *  接口地址：https://res.decerp.cc/api/UploadImg/CommonImg
   *  传输方式：POST
   *  参数说明：1.userId  代理商id
   *             2.uploadFileType 上传项目类型
   *             3.isCompress 是否压缩("true": 压缩，"false": 不压缩)
   **/
  // 提交小程序资料
  submitAppletInformation(data, myToken) {
    return axios({
      method: "POST",
      url: `WechatApply/RegisterWechat?key=${myToken}`,
      headers: {
        "Content-Type": "application/json; charset=utf-8"
      },
      data
    }).then(res => {
      return res.data
    })
  },

  // 支付申请记录页面
  // 支付申请审核
  paymentApplicationAudit(id, shop_uid, status, myToken) {
    return axios({
      url: `/UserInfo/PTApprovePayApplication?user_id=47116375&id=${id}&shop_uid=${shop_uid}&status=${status}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 新增支付资料页面
  // 提交支付资料
  submitPaymentInformation(data, myToken) {
    return axios({
      method: "POST",
      url: `WechatApply/RegisterPay?key=${myToken}`,
      headers: {
        "Content-Type": "application/json; charset=utf-8"
      },
      data
    }).then(res => {
      return res.data
    })
  },

  // 支付申请资料页面
  // 获取支付资料列表
  getPaymentInformationList(page, pagesize, myToken) {
    return axios({
      url: `/UserInfo/PTGetAlipayApplicationList?page=${page}&pagesize=${pagesize}&applyType=-1&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 支付资料审核
  paymentInformationAudit(sv_alipayinfo_id, sv_state, remark, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTOpAlipayApplication?sv_alipayinfo_id=${sv_alipayinfo_id}&sv_state=${sv_state}&remark=${remark}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 待办事项页面接口 ----------------

  // 账户信息页面接口 ----------------
  // 个人资料页面
  // 上传图片
  uploadPictures(data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTUploadLogoFilesAjax?key=${myToken}&img_name=logo`,
      contentType: false,
      processData: false,
      data
    }).then(res => {
      return res.data
    });
  },

  // 修改密码页面
  // 修改密码
  changePassword(data, myToken) {
    return axios({
      url: `/UserInfo/PTUpdateUserInfo?key=${myToken}`,
      method: "POST",
      data
    }).then(res => {
      return res.data
    })
  },

  // 短信充值页面
  // 获取短信套餐
  getSmsPackage(myToken) {
    return axios({
      url: `/UserInfo/GetPTSMSPackage?key=${myToken}`
    }).then(res => {
      return res.data
    });
  },
  // 短信在线充值
  smsOnlineRecharge(data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTSaveSns_Dec_Order?key=${myToken}`,
      data
    }).then(res => {
      return res.data
    })
  },

  // 角色管理页面
  // 获取角色列表
  getRoleList(page, pagesize, myToken) {
    return axios({
      url: `/UserInfo/PTGetDistributorRoleList?page=${page}&pagesize=${pagesize}&key=${myToken}`
    }).then(res => {
      return res.data.values
    })
  },
  // 保存权限设置
  savePermissionSettings(data, distributor_id, sv_d_role_id, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTUpdateDistributorRoleConfig?distributor_id=${distributor_id}&sv_d_role_id=${sv_d_role_id}&key=${myToken}`,
      data
    }).then(res => {
      return res
    })
  },
  // 新建角色
  creatingRoles(data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTAddDistributorRole?key=${myToken}`,
      data
    }).then(res => {
      return res.data
    })
  },
  // 改变角色状态
  changeRolesStatus(sv_d_role_id, sv_enabled, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTOpterDistributorRole?sv_d_role_id=${sv_d_role_id}&sv_enabled=${sv_enabled}&key=${myToken}`
    }).then(res => {
      return res
    })
  },
  // 删除角色
  deleteRole(sv_d_role_id, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTDelDistributorRole?sv_d_role_id=${sv_d_role_id}&key=${myToken}`
    }).then(res => {
      return res
    })
  },

  // 用户管理页面
  // 获取员工列表
  getStaffList(page, pagesize, myToken) {
    return axios({
      url: `/UserInfo/PTGetDistributorUserList?page=${page}&pagesize=${pagesize}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 新增/修改员工信息
  handleStaffInfo(data, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTAddDistributorUser?key=${myToken}`,
      data
    }).then(res => {
      return res.data
    })
  },
  // 检测账号是否已存在
  testAccountWhetherExist(sv_d_user_account_no, myToken) {
    return axios({
      url: `/UserInfo/CheckAddDistributorUserAccountExist?sv_d_user_account_no=${sv_d_user_account_no}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 改变账号状态
  changeAccountStatus(sv_d_user_id, sv_enabled, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTOpterDistributorUser?sv_d_user_id=${sv_d_user_id}&sv_enabled=${sv_enabled}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 删除账号
  deleteAccount(sv_d_user_id, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTDelDistributorUser?sv_d_user_id=${sv_d_user_id}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 操作日志页面
  // 获取日志列表
  getLogList(page, pagesize, keywards, start, end, myToken) {
    return axios({
      url: `/UserInfo/PTGetDistributorOptLog?page=${page}&pagesize=${pagesize}&keywards=${keywards}&start=${start}&end=${end}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 支付配置页面
  // 配置支付
  configPayment(data, config, type, myToken) {
    return axios({
      url: `/UserInfo/PTUpdateDistributorPayConfig?type=${type}&config=${config}&key=${myToken}`,
      method: "POST",
      data
    }).then(res => {
      return res.data
    })
  },

  // 主页自定义页面
  // 获取主页配置
  getHomepageConfig(myToken) {
    return axios({
      url: `/UserInfo/PTGetCustom_config?key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 保存主页配置
  saveHomepageConfig(data) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTUpdateCustom_config`,
      data
    }).then(res => {
      return res.data
    })
  },
  // 上传主页图片
  uploadMainPicture(data, img_name, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTUploadCustomFilesAjax?img_name==${img_name}&key=${myToken}`,
      contentType: false,
      processData: false,
      data
    }).then(res => {
      return res.data
    })
  },
  // 账户信息页面接口 ----------------

  // 结算中心页面接口 ----------------
  // 结算明细页面
  // 获取结算明细列表
  getBillingDetailsList(page, pageSize, condition, type, myToken) {
    return axios({
      url: `/UserInfo/PTmoney?page=${page}&pagesize=${pageSize}&condition=${condition}&type=${type}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 撤销订单
  backoutOrder(user_id, order_id, myToken) {
    return axios({
      method: "POST",
      url: `/UserInfo/PTOrderRecove?user_id=${user_id}&order_id=${order_id}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 余额变动页面
  // 获取余额变动列表
  getBalanceChangeList(page, pagesize, myToken) {
    return axios({
      url: `/UserInfo/PTGetDistributorWalletCostList?page=${page}&pagesize=${pagesize}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },

  // 短信变动页面
  // 获取短信变动列表
  getSmsChangeList(page, pagesize, myToken) {
    return axios({
      url: `/UserInfo/PTGetDealerRecordPageList/?page=${page}&pagesize=${pagesize}&key=${myToken}`
    }).then(res => {
      return res.data
    })
  },
  // 账户信息页面接口 ----------------

  // 帮助中心页面接口 ----------------
  // 常见问题页面
  // 获取常见问题列表
  getFamiliarProblemList() {
    return axios({
      url: "http://www.decerp.cn/api/DecHelp/helpCategray_All",
    }).then(res => {
      return res
    })
  },
  // 帮助中心页面接口 ----------------

  // 需求管理页面接口 ----------------
  // 获取需求列表
  getDemandList(paramter, myToken) {
    return axios({
      url: `/WorkOrder/GetQuery?Page=${paramter.Page}&PageSize=${paramter.PageSize}&sv_master_id=${paramter.sv_master_id}&sv_priority=${paramter.sv_priority}&sv_type=${paramter.sv_type}&sv_createtime_begin=${paramter.sv_createtime_begin}&sv_createtime_end=${paramter.sv_createtime_end}&sv_endtime_begin=${paramter.sv_endtime_begin}&sv_endtime_end=${paramter.sv_endtime_end}&sv_client_type=${paramter.sv_client_type}&sv_status=${paramter.sv_status}&Query=${paramter.Query}&key=${myToken}`
    }).then(res => {
      const {
        succeed,
        values
      } = res.data
      if (succeed) {
        return values
      } else {
        Promise.reject(res)
      }
    });
  },
  // 新增/更新需求
  addDemand(data, myToken) {
    return axios({
      url: `/WorkOrder/Update?key=${myToken}`,
      method: "POST",
      headers: {
        "Content-Type": "application/json; charset=utf-8"
      },
      data
    }).then(res => {
      return res.data
    });
  },
  // 获取需求详情
  getDemandDetail(id, myToken) {
    return axios({
      url: `/WorkOrder/Get?id=${id}&key=${myToken}`,
    }).then(res => {
      return res.data
    });
  },
  // 删除需求订单
  deleteDemandOrder(id, myToken) {
    return axios({
      url: `/WorkOrder/Delete?id=${id}&key=${myToken}`,
      method: "POST",
    }).then(res => {
      return res.data
    });
  },
  // 获取状态数统计
  getStateCountStatistics(paramter, myToken) {
    return axios({
      url: `/WorkOrder/GetStatusTotal?Page=${paramter.Page}&PageSize=${paramter.PageSize}&sv_master_id=${paramter.sv_master_id}&sv_priority=${paramter.sv_priority}&sv_type=${paramter.sv_type}&sv_createtime_begin=${paramter.sv_createtime_begin}&sv_createtime_end=${paramter.sv_createtime_end}&sv_endtime_begin=${paramter.sv_endtime_begin}&sv_endtime_end=${paramter.sv_endtime_end}&sv_client_type=${paramter.sv_client_type}&sv_status=${paramter.sv_status}&key=${myToken}`,
    }).then(res => {
      return res.data
    });
  }
  // 需求管理页面接口 ----------------
}
